<body>
<script src="js/myJS/register.js"></script>
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-content">
                    <form id="registerInfo">
                        <div class="form-group  row">
                            <label class="col-sm-2 col-form-label">发票号：</label>
                            <div class="col-sm-10"><input type="text" class="form-control" name="invoiceID"
                                                          readonly="readonly"></div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div><h4>挂号信息</h4></div>
                        <div class="form-group  row">
                            <label class="col-sm-2 col-form-label">病历号：</label>
                            <div class="col-sm-10"><input type="text" class="form-control" name="medicalRecordID"
                                                          data-rule='required:true|numeric:true'>
                                <div style="color: red;display: none" id="medicalRecordID-input-error">病历号不能为空，且应为数字
                                </div>
                            </div>

                        </div>
                        <div class="form-group  row">
                            <label class="col-sm-2 col-form-label">姓名：</label>
                            <div class="col-sm-10"><input type="text" class="form-control" name="name"
                                                          data-rule='required:true|minlength:2|maxlength:20'>
                                <div style="color: red;display: none" id="name-input-error">姓名不能为空，长度区间：2-20</div>
                            </div>
                        </div>
                        <div class="form-group row"><label class="col-sm-2 col-form-label">性别：</label>
                            <div class="col-sm-10"><select class="form-control m-b" name="gender">
                                <option>男</option>
                                <option>女</option>
                            </select>
                            </div>
                        </div>
                        <div class="form-group  row">
                            <label class="col-sm-2 col-form-label">年龄：</label>
                            <div class="col-sm-10"><input type="text" class="form-control" name="age"
                                                          data-rule='required:true|numeric:true|min:1|max:150'>
                                <div style="color: red;display: none" id="age-input-error">年龄不能为空，且应为数字，填写区间：1-150</div>
                            </div>
                        </div>
                        <div class="form-group row"><label class="col-sm-2 col-form-label">年龄类别：</label>
                            <div class="col-sm-10"><select class="form-control m-b" name="ageType">
                                <option>岁</option>
                                <option>月</option>
                                <option>日</option>
                            </select>
                            </div>
                        </div>
                        <div class="form-group  row">
                            <label class="col-sm-2 col-form-label">出生日期：</label>
                            <div class="col-sm-10"><input type="date" class="form-control" name="birthday"
                                                          data-rule="beforeIncludeToday:true">
                                <div style="color: red;display: none" id="birthday-input-error">出生日期应小于等于今日</div>
                            </div>
                        </div>
                        <div class="form-group  row">
                            <label class="col-sm-2 col-form-label">身份证号：</label>
                            <div class="col-sm-10"><input type="text" class="form-control" name="numID"
                                                          data-rule='fixedLength:18'>
                                <div style="color: red;display: none" id="numID-input-error">身份证格式错误</div>
                            </div>
                        </div>
                        <div class="form-group  row">
                            <label class="col-sm-2 col-form-label">家庭住址：</label>
                            <div class="col-sm-10"><input type="text" class="form-control" name="address" required="">
                            </div>
                        </div>
                        <div class="form-group row"><label class="col-sm-2 col-form-label">结算类别：</label>
                            <div class="col-sm-10"><select class="form-control m-b" name="chargeType">
                                <option>自费</option>
                                <option>市医保</option>
                            </select>
                            </div>
                        </div>
                        <div class="form-group  row">
                            <label class="col-sm-2 col-form-label">看诊日期：</label>
                            <div class="col-sm-10"><input type="date" class="form-control" name="registerDate"
                                                          data-rule='afterIncludeToday:true|required:true'>
                                <div style="color: red;display: none" id="registerDate-input-error">看诊日期应大于等于今日</div>
                            </div>
                        </div>
                        <div class="form-group row"><label class="col-sm-2 col-form-label">午别：</label>
                            <div class="col-sm-10"><select class="form-control m-b" name="registerNoon">
                                <option>上午</option>
                                <option>下午</option>
                            </select>
                            </div>
                        </div>
                        <div class="form-group row"><label class="col-sm-2 col-form-label">挂号科室：</label>
                            <div class="col-sm-10"><select class="form-control m-b" name="department">
                                <option disabled selected hidden value="请选择">请选择</option>
                            </select>
                            </div>
                        </div>
                        <div class="form-group row"><label class="col-sm-2 col-form-label">号别：</label>
                            <div class="col-sm-10"><select class="form-control m-b" name="registerLevel">
                                <option>普通号</option>
                                <option>专家号</option>
                            </select>
                            </div>
                        </div>
                        <div class="form-group row"><label class="col-sm-2 col-form-label">看诊医生：</label>
                            <div class="col-sm-10"><select class="form-control m-b" name="doctorID">
                                <option disabled selected hidden value="请选择">请选择</option>
                            </select>
                            </div>
                        </div>
                        <div class="form-group  row">
                            <label class="col-sm-2 col-form-label">初始号额：</label>
                            <div class="col-sm-10"><input type="text" class="form-control" name="registerNum"
                                                          readonly="readonly"></div>
                        </div>
                        <div class="form-group  row">
                            <label class="col-sm-2 col-form-label">已挂号额：</label>
                            <div class="col-sm-10"><input type="text" class="form-control" name="registerUsedNum"
                                                          readonly="readonly"></div>
                        </div>
                        <div class="form-group row"><label class="col-sm-2 col-form-label">是否需要病历本：</label>
                            <div class="col-sm-10"><select class="form-control m-b" name="medicalBook">
                                <option>是</option>
                                <option>否</option>
                            </select>
                            </div>
                        </div>
                        <div class="form-group  row">
                            <label class="col-sm-2 col-form-label">应收金额：</label>
                            <div class="col-sm-10"><input type="text" class="form-control fixed" name="money" value="8"
                                                          readonly="readonly"></div>
                        </div>
                        <div class="form-group row"><label class="col-sm-2 col-form-label">收费方式：</label>
                            <div class="col-sm-10"><select class="form-control m-b" name="chargeWay">
                                <option>现金</option>
                                <option>医保卡</option>
                                <option>银行卡</option>
                                <option>信用卡</option>
                                <option>微信</option>
                                <option>支付宝</option>
                                <option>云闪付</option>
                                <option>其他</option>
                            </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group row">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button class="btn btn-white btn-sm" type="reset" margin="padding-right: 20px">清空
                                </button>
                                <button class="btn btn-primary btn-sm" type="button" id="registerSubmit">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="js/myJS/validator.js"></script>
<script src="js/myJS/input.js"></script>
<script src="js/myJS/main.js"></script>
<script>
    //将表单数据序列化并加入医生ID
    $.fn.serializeObject = function () {
        var obj = {};
        var formArray = this.serializeArray();
        for (var i = 0; i < formArray.length; i++) {
            obj[formArray[i].name] = formArray[i]['value'];
        }
        obj['registerUserID'] = [[${session.userID}]];
        return obj;
    };
    //挂号操作
    $(document).ready(function () {
        $("#registerSubmit").click(function () {
            let formData = $("#registerInfo").serializeObject();
            if (submit_validate()) {
                if ($("select[name='department']").val() == null) {
                    $('.alert').html('就诊科室不能为空').addClass('alert-warning').show().delay(1400).fadeOut();
                    return;
                }
                if ($("select[name='doctorID']").val() == null) {
                    $('.alert').html('就诊医生不能为空').addClass('alert-warning').show().delay(1400).fadeOut();
                    return;
                }
                $.ajax({
                    url: "/register",
                    type: "post",
                    contentType: "application/json",
                    dataType: "json",
                    data: JSON.stringify(formData),
                    success: function () {
                        $('.alert').html('挂号成功').addClass('alert-success').show().delay(1400).fadeOut();

                        $.ajax({
                            url: "register.html", //这里是静态页的地址
                            type: "GET", //静态页用get方法，否则服务器会抛出405错误
                            success: function (register) {
                                $("#hideElement").html(register);
                            }
                        });
                    }
                });
            } else {
                $('.alert').html('挂号失败').addClass('alert-warning').show().delay(1400).fadeOut();
            }
        });
    });
</script>
</body>